#!/bin/bash

export DNS_SERVER=$(cat /etc/resolv.conf |grep -i '^nameserver'|cut -d ' ' -f2|tr '\n' ' ')
envsubst < /app/conf/nginx.template > /app/conf/nginx.conf

mkdir -p /app/logs

# forward request and error logs to docker log collector
ln -sf /dev/stdout /app/logs/access.log
ln -sf /dev/stderr /app/logs/error.log

# start openresty
if [[ -z ${1} ]]; then
  echo "Starting openresty..."
  exec /usr/local/openresty -g "daemon off;"
else
  exec "$@"
fi
